1 module hip.jni.android.asset_manager; 2 version(Android): 3 extern(C): 4 alias off_t = int; 5 alias off64_t = long; 6 7 /* 8 * Copyright (C) 2010 The Android Open Source Project 9 * 10 * Licensed under the Apache License, Version 2.0 (the "License"); 11 * you may not use this file except in compliance with the License. 12 * You may obtain a copy of the License at 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 16 * Unless required by applicable law or agreed to in writing, software 17 * distributed under the License is distributed on an "AS IS" BASIS, 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 * See the License for the specific language governing permissions and 20 * limitations under the License. 21 */ 22 23 /** 24 * @addtogroup Asset 25 * @{ 26 */ 27 28 /** 29 * @file asset_manager.h 30 */ 31 32 33 34 // #if !defined(__ANDROID__) && !defined(__RENAME_IF_FILE_OFFSETd64) 35 // #define __RENAME_IF_FILE_OFFSETd64(x) 36 // #endif 37 38 /** 39 * {@link AAssetManager} provides access to an application's raw assets by 40 * creating {@link AAsset} objects. 41 * 42 * AAssetManager is a wrapper to the low-level native implementation 43 * of the java {@link AAssetManager}, a pointer can be obtained using 44 * AAssetManager_fromJava(). 45 * 46 * The asset hierarchy may be examined like a filesystem, using 47 * {@link AAssetDir} objects to peruse a single directory. 48 * 49 * A native {@link AAssetManager} pointer may be shared across multiple threads. 50 */ 51 struct AAssetManager; 52 53 /** 54 * {@link AAssetDir} provides access to a chunk of the asset hierarchy as if 55 * it were a single directory. The contents are populated by the 56 * {@link AAssetManager}. 57 * 58 * The list of files will be sorted in ascending order by ASCII value. 59 */ 60 struct AAssetDir; 61 62 /** 63 * {@link AAsset} provides access to a read-only asset. 64 * 65 * {@link AAsset} objects are NOT thread-safe, and should not be shared across 66 * threads. 67 */ 68 struct AAsset; 69 70 /** Available access modes for opening assets with {@link AAssetManager_open} */ 71 enum { 72 /** No specific information about how data will be accessed. **/ 73 AASSET_MODE_UNKNOWN = 0, 74 /** Read chunks, and seek forward and backward. */ 75 AASSET_MODE_RANDOM = 1, 76 /** Read sequentially, with an occasional forward seek. */ 77 AASSET_MODE_STREAMING = 2, 78 /** Caller plans to ask for a read-only buffer with all data. */ 79 AASSET_MODE_BUFFER = 3 80 } 81 82 83 /** 84 * Open the named directory within the asset hierarchy. The directory can then 85 * be inspected with the AAssetDir functions. To open the top-level directory, 86 * pass in "" as the dirName. 87 * 88 * The object returned here should be freed by calling AAssetDir_close(). 89 */ 90 AAssetDir* AAssetManager_openDir(AAssetManager* mgr, const char* dirName); 91 92 /** 93 * Open an asset. 94 * 95 * The object returned here should be freed by calling AAsset_close(). 96 */ 97 AAsset* AAssetManager_open(AAssetManager* mgr, const char* filename, int mode); 98 99 /** 100 * Iterate over the files in an asset directory. A NULL string is returned 101 * when all the file names have been returned. 102 * 103 * The returned file name is suitable for passing to AAssetManager_open(). 104 * 105 * The string returned here is owned by the AssetDir implementation and is not 106 * guaranteed to remain valid if any other calls are made on this AAssetDir 107 * instance. 108 */ 109 const (char)* AAssetDir_getNextFileName(AAssetDir* assetDir); 110 111 /** 112 * Reset the iteration state of AAssetDir_getNextFileName() to the beginning. 113 */ 114 void AAssetDir_rewind(AAssetDir* assetDir); 115 116 /** 117 * Close an opened AAssetDir, freeing any related resources. 118 */ 119 void AAssetDir_close(AAssetDir* assetDir); 120 121 /** 122 * Attempt to read 'count' bytes of data from the current offset. 123 * 124 * Returns the number of bytes read, zero on EOF, or < 0 on error. 125 */ 126 int AAsset_read(AAsset* asset, void* buf, size_t count); 127 128 /** 129 * Seek to the specified offset within the asset data. 'whence' uses the 130 * same constants as lseek()/fseek(). 131 * 132 * Uses 64-bit data type for large files as opposed to the 32-bit type used 133 * by AAsset_seek. 134 * 135 * Returns the new position on success, or (off64_t) -1 on error. 136 */ 137 off64_t AAsset_seek64(AAsset* asset, off64_t offset, int whence); //AAset_seek64 138 /** 139 * Seek to the specified offset within the asset data. 'whence' uses the 140 * same constants as lseek()/fseek(). 141 * 142 * Returns the new position on success, or (off_t) -1 on error. 143 */ 144 off_t AAsset_seek(AAsset* asset, off_t offset, int whence); 145 146 /** 147 * Close the asset, freeing all associated resources. 148 */ 149 void AAsset_close(AAsset* asset); 150 151 /** 152 * Get a pointer to a buffer holding the entire contents of the assset. 153 * 154 * Returns NULL on failure. 155 */ 156 const (void*) AAsset_getBuffer(AAsset* asset); 157 158 159 /** 160 * Report the total size of the asset data. Reports the size using a 64-bit 161 * number insted of 32-bit as AAsset_getLength. 162 */ 163 off64_t AAsset_getLength64(AAsset* asset); 164 /** 165 * Report the total size of the asset data. 166 */ 167 off_t AAsset_getLength(AAsset* asset); 168 169 /** 170 * Report the total amount of asset data that can be read from the current position. 171 * 172 * Uses a 64-bit number instead of a 32-bit number as AAsset_getRemainingLength does. 173 */ 174 off64_t AAsset_getRemainingLength64(AAsset* asset); 175 /** 176 * Report the total amount of asset data that can be read from the current position. 177 */ 178 off_t AAsset_getRemainingLength(AAsset* asset); 179 180 /** 181 * Open a new file descriptor that can be used to read the asset data. 182 * 183 * Uses a 64-bit number for the offset and length instead of 32-bit instead of 184 * as AAsset_openFileDescriptor does. 185 * 186 * Returns < 0 if direct fd access is not possible (for example, if the asset is 187 * compressed). 188 */ 189 int AAsset_openFileDescriptor64(AAsset* asset, off64_t* outStart, off64_t* outLength); 190 /** 191 * Open a new file descriptor that can be used to read the asset data. If the 192 * start or length cannot be represented by a 32-bit number, it will be 193 * truncated. If the file is large, use AAsset_openFileDescriptor64 instead. 194 * 195 * Returns < 0 if direct fd access is not possible (for example, if the asset is 196 * compressed). 197 */ 198 int AAsset_openFileDescriptor(AAsset* asset, off_t* outStart, off_t* outLength); 199 200 /** 201 * Returns whether this asset's internal buffer is allocated in ordinary RAM (i.e. not 202 * mmapped). 203 */ 204 int AAsset_isAllocated(AAsset* asset);